package specificGameObject;

import component.*;
import general.GeneralTool;
import system.*;
import vector.*;

public class Mouse extends DraggableObject
{
	private double timer = 0;
	private Vector2 velocity_perFrame;
	private double movetime = 3;
	private boolean b_direction =true;

	public void setVelocity(Vector2 velocity)
	{
		velocity_perFrame = velocity.multiply(Time.fixedDeltaTime);
	}

	public Mouse(Vector2 _position)
	{
		super(_position);
		setVelocity(new Vector2(-100,0));
		if (_position.x<300) 
			setPosition(new Vector2(_position.x+300,_position.y));
		if (_position.x>1600) 
			setPosition(new Vector2(_position.x-300, _position.y));
		addSpriteRenderer("Image/mousel.png",new Vector2(66,46),-1);
		addBoxCollider(new Vector2(9,9),new Vector2(50,30), Layer.DragbleObject,Layer.Claw);
		price = 2;
		dragSpeed = 500;
		timer = GeneralTool.randomRange(0, movetime);
	}

	public void fixedUpdate()
	{
		timer += Time.fixedDeltaTime;
		if (timer < movetime)
		{
			if(b_direction)
				setPosition(getPosition().add(velocity_perFrame));
			else
				setPosition(getPosition().subtract(velocity_perFrame));
		}
		else
		{
			if (b_direction)
			{
			    addSpriteRenderer("Image/mouser.png",new Vector2(66,46),-1);
				b_direction = false;
				timer = 0;
			}
			else
			{
				addSpriteRenderer("Image/mousel.png",new Vector2(66,46),-1);
				b_direction = true;
				timer = 0;
			}
		}
	}
}
